package com.workcell.workdata.xthings.dto;

import com.github.pagehelper.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 分页类
 *
 * @author Shichimi
 */
@Data
@ApiModel(value = "PageVO", description = "分页参数")
public class PageVo implements IPage {
    /**
     * 默认当前页为第一页
     */
    private static final Integer DEFAULT_PAGE_NUM = 1;
    /**
     * 默认分页大小
     */
    private static final Integer DEFAULT_PAGE_SIZE = 10;
    /**
     * 最大分页大小
     */
    private static final Integer MAX_PAGE_SIZE = 100;

    /**
     * 当前页
     */
    @ApiModelProperty(value = "当前页")
    private Integer pageNum;
    /**
     * 分页大小
     */
    @ApiModelProperty(value = "分页大小")
    private Integer pageSize;

    @ApiModelProperty(value = "排序字段名称")
    private String orderBy;

    public Integer getPageNum() {
        if (this.pageNum == null || this.pageNum < 1) {
            return DEFAULT_PAGE_NUM;
        } else {
            return this.pageNum;
        }
    }

    public Integer getPageSize() {
        if (pageSize == null || pageSize < 1) {
            return DEFAULT_PAGE_SIZE;
        } else if (pageSize > MAX_PAGE_SIZE) {
            return MAX_PAGE_SIZE;
        } else {
            return this.pageSize;
        }
    }
}
